export const COS_CDN_URL = process.env.NODE_ENV === 'development' ? 'https://test-1257832417.cos.ap-guangzhou.myqcloud.com' : 'https://booking-1257832417.cos.ap-nanjing.myqcloud.com'

export const downloadCosImg = async (url, name) => {
  const blob = await ((await fetch(url)).blob())
  const blobUrl = URL.createObjectURL(blob)
  const a = document.createElement('a')
  a.style.display = 'none'
  a.href = blobUrl
  a.download = name
  document.body.appendChild(a)
  a.click()
  a.remove()
  window.URL.revokeObjectURL(blobUrl)
}

export const convertUrl =(url) => {
  if(url == null || url == undefined || url == ''){
    return ''
  } 
  if(url.startsWith("https://")){
    return url
  }
  return COS_CDN_URL + url
}

export const subUrl = (url) =>{
  if(url == null || url == undefined || url == ''){
    return ''
  } 
  return url;
}